<?php
	namespace Common\Logic;
	use Common\Model\UserLevelModel;
	class UserLevelLogic extends UserLevelModel{
		/*
		* Function:		getUserLevelList
		* Description:	用户等级列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getUserLevelList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getUserLevelFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getUserLevelFilter
		* Description:	用户等级列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getUserLevelFilter($filter = ''){
			$conditon = array();
			if(!empty($filter['nid'])){
				$conditon['nid'] = array('in',$filter['nid']);
			}
			if(!empty($filter['content'])){
				$conditon['content'] = array('like','%'.$filter['content'].'%');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getUserLevelCount
		* Description:	用户等级列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getUserLevelCount($filter = ''){
			$conditon = $this->getUserLevelFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addUserLevel
		* Description:	增加用户等级
		* @param:		$data array 增加的数组
		*/
		public function addUserLevel($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getUserLevelInfo
		* Description:	获取用户等级信息 by row
		* @param:		$id int ID
		*/
		public function getUserLevelInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateUserLevel
		* Description:	更新用户等级
		* @param:		$data array 更新的数组
		*/
		public function updateUserLevel($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteUserLevel
		* Description:	删除用户等级
		* @param:		$id int ID
		*/
		public function deleteUserLevel($id){
			return $this->where(array('id'=>$id))->delete();
		}
	}
?>